<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<base href="<%=basePath%>">
<%@ include file="/base/jsp/include.jsp"%>
<script type="text/javascript">
    var grid;
    var addFun = function() {
        var dialog = parent.sy.modalDialog({
            title : '添加载体',
            width : 800,
            height : 600,
            url : sy.contextPath + '/go.do?path=zaitiEdit/zaitiEdit',
            buttons : [ {
                text : '添加',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
    };
    var editFun = function() {
        var rows = grid.datagrid('getSelections');
        if (rows.length != 1) {
            parent.$.messager.w('请选择一条记录进行编辑！');
            return;
        }
        var dialog = parent.sy.modalDialog({
            title : '编辑焦点图信息',
            width : 800,
            height : 600,
            url : sy.contextPath + '/go.do?path=zaitiEdit/zaitiEdit&id=' + rows[0].id,
            buttons : [ {
                text : '编辑',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
    };
    var delFun = function() {
        var rows = grid.datagrid('getSelections');
        if (rows.length == 0) {
            parent.$.messager.w('请选择需要删除的记录！');
            return;
        }
        parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
            if (r) {
                var ids = [];
                for ( var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.id);
                }
                var id = ids.join(',');
                
                $.post(sy.contextPath + '/companyRegister/del.do', {
                    id : id
                }, function() {
                    rows.length = 0;//必须，否则有bug
                    grid.datagrid('reload');
                }, 'json');
            }
        });
    };
    $(function() {
        
        var menu;
        menu={
                url : sy.contextPath + '/companyRegister/list.do',
                toolbar : '#toolbar',
                singleSelect : false,
                columns : [ [ {
                    width : $(this).width() * 0.1,
                    title : '工商登记名称',
                    field : 'registerName',
                    align : 'center'
                }, {
                    width : $(this).width()*0.1,
                    title : '企业名称',
                    field : 'companyName',
                    align : 'center',
                }, {
                    width : $(this).width()*0.1,
                    title : '项目标题',
                    field : 'title',
                    align : 'center',
                }, {
                    width : $(this).width() * 0.1,
                    title : '地址',
                    field : 'address',
                    align : 'center',
                }, {
                    width : $(this).width() * 0.1,
                    title : '注册资金(万元)',
                    field : 'registerMoney',
                    align : 'center',
                }, {
                    width : $(this).width() * 0.1,
                    title : '注册日期',
                    field : 'registerDate',
                    align : 'center',
                    formatter : function(value, row, index) {
                        if(row.registerDate){
                        	return row.registerDate.substring(0,10);
                        }
                    }
                }, {
                    width : $(this).width() * 0.1,
                    title : '法人代表',
                    field : 'master',
                    align : 'center',
                }, {
                    width : $(this).width() * 0.1,
                    title : '联系电话',
                    field : 'phone',
                    align : 'center',
                }, {
                    width : $(this).width() * 0.1,
                    title : '经营范围',
                    field : 'ranges',
                    align : 'center',
                }, {
                    width : $(this).width()*0.1,
                    title : '状态',
                    field : 'isAgree',
                    align : 'center',
                    formatter : function(value, row, index) {
                        if(value == 0){
                            return  '<a href="javascript:void(0);"  style="color:red" title="未审核">未审核</a>';
                        }else if(value == 1){
                            return  '<a href="javascript:void(0);"  ><img src="base/images/yes.png" title="审核通过" > </img></a>';
                        }else if(value == 2){
                            return  '<a href="javascript:void(0);"  ><img src="base/images/no.png" title="审核不通过" > </img></a>';
                        }
                    }
                }, {
                    width : $(this).width()*0.1,
                    title : '项目是否终止',
                    field : 'isProjectEnable',
                    align : 'center',
                    formatter : function(value, row, index) {
                        if(value == 0){
                            return  '否';
                        }else if(value == 1){
                            return  '是';
                        }else
                        {
                            return value;
                        }
                    }
                }, {
                    width : $(this).width()*0.2,
                    title : '操作',
                    field : 'isAgrees',
                    align : 'center',
                    formatter : function(value, row, index) {
                    	if(row.isAgree == 1 || row.isAgree == 2){
                            return  '<a href="javascript:void(0);" style="color:red" >该项目已经审核过了！</a>';
                        }else if(row.isAgree == 0){
                        	return '<a><button onclick="forbidden(1,\''+row.id+'\',\''+row.projectId+'\');">审核通过</button></a><a><button onclick="forbidden(2,\''+row.id+'\',\''+row.projectId+'\');">审核不通过</button></a>';
                        }                       
                    }
                }
                ] ]
            };
        
        grid = $('#grid').datagrid(menu);
    });
    
    function forbidden(isAgree,id,projectId) {
          if(isAgree == 2){
            parent.$.messager.confirm('询问',"确定审核不通过吗？", function(r) {
                if (r) {
                    var data = {
                        id : id,
                        isAgree : 2,
                        isEnable : 1
                    };
                    var message = {
                    		projectId:projectId
                    }
                    isEnable(message,data);
                }
            });
        } else if(isAgree == 1){
            parent.$.messager.confirm('询问',"确定审核通过吗？", function(r) {
                if (r) {
                    var data = {
                        id : id,
                        isAgree : 1,
                        projectId: projectId
                    };
                    var message = {
                            projectId:projectId
                    }
                    
                    isEnables(message,id);
                }
            });
        }
    }
    function SaveData(data) {
        var url = sy.contextPath + '/companyRegister/update.do';
        $.post(url, data, function() {
            grid.datagrid('reload');
        }, 'json');
    }
    function ChooseManager(id){
        var url = sy.contextPath +'/go.do?path=companyRegisterMsg/choose&id=' + id;
        var dialog = parent.sy.modalDialog({
            title : '指派公司注册对接人',
            width : 800,
            height : 620,
            url : url,
            buttons : [ {
                text : '添加',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
   }
    
    function isEnable(message,data){
        var url = sy.contextPath + '/projectMessage/checkIsEnable.do';
        $.post(url, message, function(Result){
            if(Result.isEnable == 1){
                $.messager.alert('Warning','项目已经被终止了');
            }else if(Result.isEnable == 0){
                updateByNotAgreeReason(data.id);
            }
            grid.datagrid('reload');
        },'json')
    }
    
    function isEnables(message,id){
        var url = sy.contextPath + '/projectMessage/checkIsEnable.do';
        $.post(url, message, function(Result){
            if(Result.isEnable == 1){
                $.messager.alert('Warning','项目已经被终止了');
            }else if(Result.isEnable == 0){
            	ChooseManager(id);
            }
            grid.datagrid('reload');
        },'json')
    }

    function updateByNotAgreeReason(id){
        var url = sy.contextPath +'/go.do?path=companyRegisterMsg/notAgreeReason&id=' + id;
        var dialog = parent.sy.modalDialog({
            title : '审核不通过原因',
            width : 800,
            height : 620,
            url : url,
            buttons : [ {
                text : '确认',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
   }   
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
    <div id="toolbar" style="display: none;">
    
        <table>
            <tr>
                <td>
                    <table>
                        <tr>
                            <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_delete',plain:true" onclick="delFun();">删除</a></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <form id="searchForm">
                        <table>
                            <tr>
                                <td>企业名称：</td>
                                <td>
                                    <input type="text" class="easyui-textbox" name="name" style="width: 150px"  />
                                </td>
                                <td>
                                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
                                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
                                </td>
                            </tr>
                        </table>
                    </form>
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center',fit:true,border:false">
        <table id="grid" data-options="fit:true,border:false"></table>
    </div>
</body>
</html>